

{% extends "main/base.html" %}

{% block title %}用户信息修改{% endblock %}

{% block content %}
<div id="app">
	<table class="table table-hover form-group">
		<thead>
			<tr>
				<th>编号</th>
				<th>项目</th>
				<th>值</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>0</td>
				<td>账户</td>
				<td><span v-text="email" class="form-control"></span></td>
			</tr>
			<tr>
				<td>1</td>
				<td>姓名</td>
				<td><input v-model="name" class="form-control"></td>
			</tr>
			<tr>
				<td>2</td>
				<td>性别</td>
				<td><input v-model="sex" class="form-control"></td>
			</tr>
			<tr>
				<td>3</td>
				<td>生日</td>
				<td><input type="date" v-model="birthday" class="form-control"></td>
			</tr>
			<tr>
				<td>4</td>
				<td>电话</td>
				<td><input v-model="phone" class="form-control"></td>
			</tr>
			<tr>
				<td>5</td>
				<td>部门</td>
				<td><input v-model="department" class="form-control"></td>
			</tr>
			<tr>
				<td>6</td>
				<td>参加工作时间</td>
				<td><input type="date" v-model="job_join_time" class="form-control"></td>
			</tr>
			<tr>
				<td>7</td>
				<td>学历</td>
				<td><input v-model="education" class="form-control"></td>
			</tr>
			<tr>
				<td>8</td>
				<td>毕业院校</td>
				<td><input v-model="university" class="form-control"></td>
			</tr>
			<tr>
				<td>9</td>
				<td>毕业时间</td>
				<td><input type="date" v-model="graduate_time" class="form-control"></td>
			</tr>
		</tbody>
	</table>
	<button @click="submit" class="btn btn-primary">保存修改</button>
</div>
{% endblock %}

{% block vuejs %}
<script type="text/javascript">
	var vm = new Vue({
		el: '#app',
		data:{
			email: '{{ request.user.email }}',
			name: '{{ request.user.name }}',
			sex: '{{ request.user.sex }}',
			birthday: '{{ request.user.birthday }}',
			phone: '{{ request.user.phone }}',
			department: '{{ request.user.department }}',
			job_join_time: '{{ request.user.job_join_time }}',
			education: '{{ request.user.education }}',
			university: '{{ request.user.university }}',
			graduate_time: '{{ request.user.graduate_time }}',
		},
		methods:{
			submit(){
				data_to_send = {
					name: this.name,
					sex: this.sex,
					birthday: this.birthday,
					phone: this.phone,
					department: this.department,
					job_join_time: this.job_join_time,
					education: this.education,
					university: this.university,
					graduate_time: this.graduate_time,
				};
				console.log(data_to_send);
				data_to_send = JSON.stringify(data_to_send);
				console.log(data_to_send);
				$.post('/accounts/profile/',
					data_to_send,
					function(r,err){
						if(err == 'success'){
							alert('修改已保存！')
							return location.assign('/');
						}else{
							return console.log(err);
						}
					});
			},
		},
	});
</script>
{% endblock %}